import { defineStore } from 'pinia'
import * as api from '@/api/dict_data'

export const dictDataStore = defineStore('dictData', {
  state: () => ({
    dictDataList: [],
    pagination: {
      page: 1,
      limit: 10,
      total: 0
    }
  }),

  actions: {
        async fetchDictDataPage(param) {
            const res = await api.getDataPage(param)
            this.dictDataList = res.list || []
            this.pagination.total = res.total
        },
      
        async fetchDataOne(id) {
            const res = await api.getDataOne(id)
            return res || {}
        },
    
        async addDictData(data) {
        await api.addData(data)
        },
    
        async editDictData(data) {
        await api.updateData(data)
        },
    
        async saveDictData(data) {
        return data.id ? 
                await this.editDictData(data) : 
                await this.addDictData(data)
        },
    
        async deleteDictData(id) {
        await api.deleteData(id)
        },



  }

})